
describe('Player.coffee', ->
  controller_stub = null
  target = null

  beforeEach ->
    # do nothing
    spyOn(PlayerFactory, 'create').andCallFake (controller)->
      return target
    
    controller_stub = new Controller()
    target = new Player(controller_stub)

  describe('Player class ', ->
    it 'stays idle in default', ->
      expect(target.state).toEqual('idle')

    it 'takes being publisher', ->
      target.state = 'idle'
      expect(target.is_publisher()).toEqual(false)
      target.state = 'playready'
      expect(target.is_publisher()).toEqual(true)
      target.state = 'playing'
      expect(target.is_publisher()).toEqual(true)
      target.state = 'requesting'
      expect(target.is_publisher()).toEqual(false)
      target.state = 'listening'
      expect(target.is_publisher()).toEqual(false)

    it 'notify to ui that added tunelist', ->
      tunlist_mock = new TuneList()
      target.tune_list = tunlist_mock
      file_stub =  jasmine.createSpy('FileStub')
      file_stub.name = 'sample'
      tune_sample = new Tune(file_stub, 0)

      spyOn(tunlist_mock, 'add_tune')
      spyOn(controller_stub, 'msg_changed_playlist').andCallFake (list, msg)->
          # do nothing

      target.add_tune(tune_sample)

      expect(tunlist_mock.add_tune).toHaveBeenCalled()
      expect(tunlist_mock.add_tune).toHaveBeenCalledWith(tune_sample)
      expect(controller_stub.msg_changed_playlist).toHaveBeenCalled()
  )
) 

